<?php

class Likes extends CActiveRecord
{
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'like';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id,object_id', 'required'),
			
			
			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'articles' => array(self::BELONGS_TO, 'Article', 'object_id'),
			'users' => array(self::BELONGS_TO, 'User', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'content' => 'Comment',
			'status' => 'Status',
			'created' => 'Create Time',
			'author' => 'Name',
			'email' => 'Email',
			'url' => 'Website',
			'article_id' => 'Article',
			'user_id' => 'User',
		);
	}
	public function getLikeOfUser($user_id = null,$object_id = null){
		return $this->findByAttributes(array(
			'user_id'=>$user_id,
			'object_id'=>$object_id
		));
	}
	public function selfInLike($user_id = null,$object_id = null){
		$result = $this->getLikeOfUser($user_id,$object_id);
		if(!empty($result)) return true;
		else return false;
	}
	public function getLikes($object_id){
		
		return $this->findAllByAttributes(array(
			'object_id'=>$object_id
		));
	}

	public function search() {
		
	}
	
}